package com.zhuxulin.midi.event.meta;

import java.io.IOException;
import java.io.OutputStream;

import com.zhuxulin.midi.event.MidiEvent;
import com.zhuxulin.midi.util.MidiUtil;
import com.zhuxulin.midi.util.ReadVarLen;

/**
 * FF 2F event
 * @author ZhuXulin
 */
public class EndOfTrack extends MetaEvent {

	public EndOfTrack(long tick, long delta) {
		super(tick, delta, MetaEvent.END_OF_TRACK, new ReadVarLen(0));
	}

	@Override
	protected int getEventSize() {
		return 3;
	}

	@Override
	public void writeToFile(OutputStream out) throws IOException {
		super.writeToFile(out);

		out.write(0);
	}

	@Override
	public int compareTo(MidiEvent other) {

		if (mTick != other.getTick()) {
			return mTick < other.getTick() ? -1 : 1;
		}
		if (mDelta.getValue() != other.getDelta()) {
			return mDelta.getValue() < other.getDelta() ? 1 : -1;
		}

		if (!(other instanceof EndOfTrack)) {
			return 1;
		}
		return 0;
	}
	@Override
	public byte[] getCmd() {
		cmd = new byte[]{(byte) 0xff,0x2f,0x00};
		return cmd;
	}
}
